/*
 * FoldSymmetric2x2Strategy.java
 *
 * Created on 16 de Junho de 2011, 18:42
 *
 */

package intopo.game.impl.sym2x2;

import java.io.PrintStream;

/**
 *
 * @author <a href="mailto:mariano.pedro@gmail.com">Pedro Mariano</a>
 *
 * @version 1.0 16 de Junho de 2011
 */
final public class FoldSymmetric2x2Strategy
	implements intopo.game.FoldStrategy<Symmetric2x2Strategy>
{
	/**
	 * How many strategies have been counted.
	 */
	private int count;
	/**
	 * Sum of probability to provide the good.
	 */
	private float probability;
	/**
	 * Probability average.
	 */
	private double average;

	/**
	 * Creates a new instance of FoldSymmetric2x2Strategy
	 */
	public FoldSymmetric2x2Strategy ()
	{
		start ();
	}
	public void apply (Symmetric2x2Strategy strategy)
	{
		double lastAverage = average;
		count++;
		probability += strategy.firstActionProbability;
		average = ((count - 1) * average + probability) / count;
	}
	public void print (PrintStream ps)
	{
		ps.print (this.probability);
	}
	public void start ()
	{
		count = 0;
		probability = 0;
		average = 0;
	}
}

// Local Variables:
// mode: java
// mode: flyspell-prog
// ispell-local-dictionary: "british"
// End:
